package com.itheima.config;

import com.itheima.pojo.Apple;
import com.itheima.pojo.User;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <dl>
 * <dd>描述: ~节点业务逻辑实现</dd>
 * <dd>创建时间：  11:33 2020/7/15</dd>
 * <dd>创建人： zz</dd>
 * <dt>版本历史: </dt>
 * <pre>
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2020/7/15      guodong       1.0        1.0 Version
 * </pre>
 * </dl>
 */
@Configuration //代表是一个配置类，会注入到ioc容器
public class UserConfig {

    /*
        原生注解:
            @Conditional
                注解中需要添加一个实现类condition接口的类字节码
        派生注解/衍生注解
            @ConditionalOnBean(Apple.class)：
                从当前环境中查询是否存在Apple Bean,如果存在则返回true,否则false
            @ConditionalOnMissingBean(Apple.class):
                从当前环境中查询是否存在Apple Bean,如果存在则返回false,否则true
            @ConditionalOnProperty(name = "itheima", havingValue = "26")
                从配置文件中查找key是itheima ,val是26,如果满足则返回true,如果不满足则返回false

     */

    @Bean
    public Apple apple(){
        return new Apple();
    }

    @Bean
    //@Conditional(MyCondition.class)
    //@ConditionalOnBean(Apple.class)
    //@ConditionalOnMissingBean(Apple.class)
    @ConditionalOnProperty(name = "itheima", havingValue = "26")
    public User user(){
        User user = new User();
        user.setAge(23);
        user.setName("法外狂徒张三");
        return user;
    }
}
